package com.kyp.thrift;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.apache.thrift.TException;

public class KYPHandler implements KYPService.Iface {

	@Override
	public data GetData(String type) throws TException {
		System.out.println("Type : " + type);
		
		/*
		Configuration conf = HBaseConfiguration.create();
		
		
		HTable table = null;
		try {
			table = new HTable(conf, "testtbl");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Get get = new Get(Bytes.toBytes("row1"));
		get.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("cl1"));
		
		Result rst = null;
		try {
			rst = table.get(get);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		byte[] val = rst.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("cl1"));     

		result rstCls = new result();
		rstCls.key = "row1";
		rstCls.value = Bytes.toString(val);
		*/
		
		data rtData = new data();
		rtData.rowcount = 20;
		rtData.columncount = 2;
		
		ArrayList<String> rtCol = new ArrayList<String>();
		rtCol.add("Date");
		rtCol.add("Price");
		rtData.columnkey = rtCol;
		
		ArrayList<String> date = new ArrayList<String>();
		ArrayList<String> prc = new ArrayList<String>();
		
		Random oRandom = new Random();
		oRandom.setSeed(5000);
		for(int i = 0; i < 20; i++ ){
			date.add(String.valueOf(20130901 + i));
			prc.add(String.valueOf(oRandom.nextDouble()));
		}
		
		HashMap<String, List<String>> dataT = new HashMap<String, List<String>>();
		dataT.put("Date", date);
		dataT.put("Price", prc);
		
		rtData.datatable = dataT;
		
		//Put put = new Put(Bytes.toBytes("row1"));
		//put.add(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"), Bytes.toBytes("val1"));
		//table.put(put);
		System.out.println("Return Complete!!");
		return rtData;
	}

}
